Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(docker.go): container config fields on Driver no longer pointers #206

Merged
merged 4 commits into from
May 2, 2020

Conversation

vdice
Copy link
Member

@vdice vdice commented Apr 22, 2020

  • update config fields on Driver struct to not be pointers

    • When consuming the latest code for use in Porter (to add tests around Porter's configuration options in this area), I found it problematic that some struct fields were pointers (containerCfg and containerHostCfg). I started to go down the path of creating methods in this library to return default Driver objects (NewDriver() would return a Driver with initialized/empty field references) but then I realized perhaps the code simplifications and ease of use that came with switching the fields to be actual values would be warranted here. What do reviewers think? Is there Golang best practice w/r/t fields in structs being pointers? (Avoid? Only use if initializer method(s) are provided?)
  • export ApplyConfigurationOptions

    • Porter will use this method to apply its configuration options without having to call exec on the driver in unit tests

Copy link
Contributor

@carolynvs carolynvs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that in this case, there was nothing gained by having containerHostCfg and conatinerCfg as pointers. We weren't using it to share data, represent uninitialized data, etc, and were immediately initializing it to an empty struct before calling d.ApplyConfigurationOptions() anyway. 🤷‍♀️

driver/docker/docker.go Outdated Show resolved Hide resolved
@vdice vdice force-pushed the fix/container-config branch from d7cf37d to 9b6875f Compare April 24, 2020 18:00
Signed-off-by: Vaughn Dice <[email protected]>
Copy link
Contributor

@carolynvs carolynvs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks for your patience while we worked out the mechanics of how we wanted this to work for users of the library!

@@ -31,15 +30,15 @@ func TestDriver_GetConfigurationOptions(t *testing.T) {
})

t.Run("configuration options", func(t *testing.T) {
d.containerCfg = &container.Config{}
d.containerHostCfg = &container.HostConfig{}
d := &Driver{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 this is much cleaner to work with

Copy link
Contributor

@silvin-lubecki silvin-lubecki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@silvin-lubecki silvin-lubecki merged commit 1db08a3 into cnabio:master May 2, 2020
@vdice vdice deleted the fix/container-config branch May 4, 2020 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants